# -*- coding: utf-8 -*-
# @Author：fanmingxiang@touty.io
# @Date  ：2022/2/23 16:22
import os
import time

from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
from appium import webdriver
from time import sleep


from config import BASE_PATH

desired_caps = {
    "platformName": "Android",
    "platformVersion": "10",
    "deviceName": "xxx",
    "appPackage": "com.tencent.mm",
    "appActivity": ".ui.LauncherUI",
    "noReset": True,
    "automationName": "UiAutomator2",
    "chromeOptions": {'androidProcess': 'com.tencent.mm:toolsmp'}
}
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

driver.implicitly_wait(5)

# driver.find_element(By.XPATH, "//*[@text='智能零售平台']").click()
# driver.find_element(By.XPATH, '(//*[@text="京东悦鲜活12元满减券表单"])[last()]').click()
# print(driver.get_window_size())
# sleep(2)
# driver.switch_to.context('WEBVIEW_com.tencent.mm:toolsmp')
# driver.switch_to.window(driver.window_handles[0])
# sleep(3)
# print(driver.current_url)
# driver.find_element(By.CSS_SELECTOR, '.start-btn').click()

# document_time_name = time.strftime("%Y-%m-%d", time.localtime(time.time()))
# picture_time_name = time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime(time.time()))
# file_path = BASE_PATH + os.sep + 'image' + os.sep + document_time_name
# if not os.path.exists(file_path):
#     os.makedirs(file_path)
# filepath = file_path + os.sep + picture_time_name + '.png'
# driver.get_screenshot_as_file(filepath)


document_time_name = time.strftime("%Y-%m-%d", time.localtime(time.time()))
picture_time_name = time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime(time.time())) + '.png'
document_path = BASE_PATH + os.sep + 'image' + os.sep + document_time_name
if not os.path.exists(document_path):
    os.makedirs(document_path)
picture_path = document_path + os.sep + picture_time_name
driver.get_screenshot_as_file(picture_path)

# driver.find_element(By.XPATH, '//*[@placeholder="输入手机号"]').send_keys('111')
# 点击返回
# driver.press_keycode(4)

